package com.example.actordemo1.remote;

import akka.actor.*;
import akka.japi.pf.DeciderBuilder;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.Duration;

@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class RemoteActor extends AbstractActor {

//    private  final SupervisorStrategy strategy = new OneForOneStrategy(3, Duration.ofSeconds(1),
//            DeciderBuilder.match(IOException.class, e -> (SupervisorStrategy.Directive) SupervisorStrategy.resume())
//                    .match(NullPointerException.class, e -> (SupervisorStrategy.Directive) SupervisorStrategy.restart())
//                    .match(IllegalArgumentException.class, e -> (SupervisorStrategy.Directive) SupervisorStrategy.stop())
//                    .matchAny(o -> (SupervisorStrategy.Directive) SupervisorStrategy.escalate())
//                    .build());
//
//
//    @Override
//    public SupervisorStrategy supervisorStrategy() {
//        return strategy;
//    }

    @Override
    public void preStart() throws Exception {
        System.out.println("RemoteActor  开始");
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder().match(String.class,msg->{
            System.out.println("进入 remote string");
            System.out.println(msg);
        }).matchAny(msg->{
            System.out.println("进入 matchAny string");
            System.out.println(msg);
        }).build();
    }

    public static void main(String[] args) {
        ActorSystem actorSystem = ActorSystem.create("sys");
        actorSystem.actorOf(Props.create(RemoteActor.class),"remoteActor");
    }

}
